#ifndef __IPC_H__
#define __IPC_H__

#include <types.h>
#include <list.h>
#include <queue.h>

#include <sys/task.h>
#include <sys/thread.h>
#include <sys/unistd.h>

extern thread_t *curth;

#define curtask		curth->owner

#define MAXOBJ_NAME	0x10
#define MAXOBJ_NUM	0x50

struct ipc {
    list_t	link;			/* link in system list */
    char	name[MAXOBJ_NAME];	/* name of IPC object */
    list_t	task_link;		/* link in task */
    queue_t	recvq;			/* the queue of receiver threads */
    queue_t	sendq;			/* the queue of sender threads */
    task_t	*owner;			/* creator task of IPC object */
};

struct msg_header {
    task_t	*task;
    int		code;
    int		status;
};

int ipc_create(const char *, ipc_t **);
int ipc_lookup(const char *, ipc_t **);
int ipc_destroy(ipc_t *);
int ipc_invalid(ipc_t *);
void ipc_cleanup(task_t *);
void ipc_init(void);

void msg_init(void);
int msg_send(ipc_t *, void *, size_t);
int msg_receive(ipc_t *, void *, size_t);
int msg_reply(ipc_t *, void *, size_t);
void msg_cancel(thread_t *);
void msg_abort(ipc_t *);

#endif	/* __IPC_H__ */
